package com.sky.controller.user;

import com.sky.entity.AddressBook;
import com.sky.result.Result;
import com.sky.service.AddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: sky-take-out
 * @description:
 * @author: fmp
 * @create: 2023-04-09 15:10
 * @Version 1.0
 **/
@RestController
@RequestMapping("/user/addressBook")
@Api(tags = "地址接口")
public class AddressBookController {
    @Resource
    private AddressBookService addressBookService;
    @GetMapping("/list")
    @ApiOperation("查询当前用户下的全部地址")
    public Result SelectAllAddressBookByUserId(){
        List<AddressBook> addressBookList =addressBookService.selectAllAddressBookByUserId();
        return Result.success(addressBookList);
    }
    @PostMapping
    @ApiOperation("新增地址")
    public Result InsertAddressBook(@RequestBody AddressBook addressBook){
        addressBookService.insertAddressBook(addressBook);
        return Result.success();

    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public Result selectById(@PathVariable Long id){
        AddressBook addressBook = addressBookService.selectById(id);
        return Result.success(addressBook);
    }
    @PutMapping
    @ApiOperation("根据id修改地址")
    public Result UpdateAddressBook(@RequestBody AddressBook addressBook){
        addressBookService.updateAddressBook(addressBook);
        return Result.success();
    }
    @DeleteMapping
    @ApiOperation("很根据id删除")
    public Result DeleteAddressBookById(Long id){
        addressBookService.DeleteAddressBookById(id);
        return Result.success();
    }
    @PutMapping("/default")
    @ApiOperation("设置默认地址")
    public Result SetDefaultAddressBook(@RequestBody AddressBook addressBook){
        addressBookService.SetDefaultAddressBook(addressBook);
        return Result.success();
    }
}
